#pragma once
#include "DXAMLCommon.h"

#include "CDependencyObject.h"
#include "Xcp_IAutomationPeer.h"


class CAutomationPeer :
	public CDependencyObject,
	public Xcp_IAutomationPeer

{

public: 
	virtual ~CAutomationPeer();
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual HRESULT InitInstance();
	virtual XUINT32 GetTypeIndex() const;
	virtual XBOOL IsUserInitiated();
	virtual struct Xcp_IDependencyObject * GetIDependencyObject();
	virtual struct IUIAWrapper * GetUIAWrapper();
	virtual void SetUIAWrapper(struct IUIAWrapper * pUIAWrapper);
	virtual struct Xcp_IAutomationPeer * GetFirstAPChild();
	virtual struct Xcp_IAutomationPeer * GetLastAPChild();
	virtual struct Xcp_IAutomationPeer * GetNextAPSibling();
	virtual struct Xcp_IAutomationPeer * GetPrevAPSibling();

	virtual CAutomationPeer * GetAPParent();

	virtual CAutomationPeer * GetAPTemplatedParentFirst();
	virtual int GetChildren(struct Xcp_IAutomationPeer * * * pppReturnAP);
	int GetRootChildren(struct Xcp_IAutomationPeer * * * pppReturnAP);
	virtual struct IUIAProvider * GetPattern(enum UIAXcp::APPatternInterface ePattern);
	virtual struct IUIATextRangeProvider * GetTextRangePattern(struct Xcp_IDependencyObject * pInteropObject);
	virtual HRESULT GetAcceleratorKey(CXString * * pRetVal);
	virtual HRESULT GetAccessKey(CXString * * pRetVal);
	virtual HRESULT GetAutomationControlType(enum UIAXcp::APAutomationControlType * pRetVal);
	virtual HRESULT GetAutomationId(CXString * * pRetVal);
	virtual HRESULT GetBoundingRectangle(struct XRECTF_WH * * pRetVal);
	virtual HRESULT GetClassNameW(CXString * *);
	virtual HRESULT GetClickablePoint(struct XPOINTF * * pRetVal);
	virtual HRESULT GetHelpText(CXString * * pRetVal);
	virtual HRESULT GetItemStatus(CXString * * pRetVal);
	virtual HRESULT GetItemType(CXString * * pRetVal);
	virtual HRESULT GetLabeledBy(struct Xcp_IAutomationPeer * * pRetVal);
	virtual HRESULT GetLocalizedControlType(CXString * * pRetVal);
	virtual HRESULT GetName(CXString * * pRetVal);
	virtual HRESULT GetOrientation(enum UIAXcp::OrientationType * pRetVal);
	virtual HRESULT GetLiveSetting(enum UIAXcp::LiveSetting * pRetVal);
	virtual HRESULT HasKeyboardFocus(XINT32 * pRetVal);
	virtual HRESULT IsContentElement(XINT32 * pRetVal);
	virtual HRESULT IsControlElement(XINT32 * pRetVal);
	virtual HRESULT IsEnabled(XINT32 * pRetVal);
	virtual HRESULT IsKeyboardFocusable(XINT32 * pRetVal);
	virtual HRESULT IsOffscreen(XINT32 * pRetVal);
	virtual HRESULT IsPassword(XINT32 * pRetVal);
	virtual HRESULT IsRequiredForForm(XINT32 * pRetVal);

	virtual CAutomationPeer * GetPeerFromPoint(struct XPOINTF * pLocation);
	virtual void InvalidatePeer();
	virtual XINT32 ListenerExists(enum UIAXcp::APAutomationEvents eventId);
	virtual void RaiseAutomationEvent(enum UIAXcp::APAutomationEvents eventId);
	virtual void RaisePropertyChangedEvent(enum UIAXcp::APAutomationProperties eAutomationProperty, CValue * oldValue, CValue * newValue);
	virtual void SetFocus();
	XUINT32 FindCachedPattern(enum UIAXcp::APPatternInterface patternType, struct Xcp_IDependencyObject * pPatternObject, struct IUIAProvider * * ppPatternProvider);
	virtual XINT32 GetChildrenCore(struct Xcp_IAutomationPeer * * * pppReturnAP);
	virtual XINT32 GetRootChildrenCore(struct Xcp_IAutomationPeer * * * pppReturnAP);
	virtual struct IUIAProvider * GetPatternCore(enum UIAXcp::APPatternInterface ePattern);
	virtual HRESULT GetAcceleratorKeyCore(CXString * * pRetVal);
	virtual HRESULT GetAccessKeyCore(CXString * * pRetVal);
	virtual HRESULT GetAutomationControlTypeCore(enum UIAXcp::APAutomationControlType * pRetVal);
	virtual HRESULT GetAutomationIdCore(CXString * * pRetVal);
	virtual HRESULT GetBoundingRectangleCore(struct XRECTF_WH * * pRetVal);
	virtual HRESULT GetClassNameCore(CXString * * pRetVal);
	virtual HRESULT GetClickablePointCore(struct XPOINTF * * pRetVal);
	virtual HRESULT GetHelpTextCore(CXString * * pRetVal);
	virtual HRESULT GetItemStatusCore(CXString * * pRetVal);
	virtual HRESULT GetItemTypeCore(CXString * * pRetVal);
	virtual HRESULT GetLabeledByCore(struct Xcp_IAutomationPeer * * pRetVal);
	virtual HRESULT GetLocalizedControlTypeCore(CXString * * pRetVal);
	virtual HRESULT GetNameCore(CXString * * pRetVal);
	virtual HRESULT GetOrientationCore(enum UIAXcp::OrientationType * pRetVal);
	virtual HRESULT GetLiveSettingCore(enum UIAXcp::LiveSetting * pRetVal);
	virtual HRESULT HasKeyboardFocusCore(XINT32 * pRetVal);
	virtual HRESULT IsContentElementCore(XINT32 * pRetVal);
	virtual HRESULT IsControlElementCore(XINT32 * pRetVal);
	virtual HRESULT IsEnabledCore(XINT32 * pRetVal);
	virtual HRESULT IsKeyboardFocusableCore(XINT32 * pRetVal);
	virtual HRESULT IsOffscreenCore(XINT32 * pRetVal);
	virtual HRESULT IsPasswordCore(XINT32 * pRetVal);
	virtual HRESULT IsRequiredForFormCore(XINT32 * pRetVal);
	virtual void SetFocusCore();
	virtual XBOOL HasParent();
	virtual void RaiseAutomaticPropertyChanges();
	virtual void RaiseAutomaticStructureChanges();
	virtual void UIElementChildAdded(struct Xcp_IDependencyObject * pDO);
	virtual void UIElementChildRemoved(struct Xcp_IDependencyObject * pDO);
	virtual XUINT32 GetRuntimeId();
	virtual void InvalidateUIAWrapper();
	virtual void InvalidateOwner();
	void NotifyManagedUIElementIsDead();
	void Deinit();
	virtual struct Xcp_IAutomationPeer * GetAPEventsSource();
	void SetAPParent(CAutomationPeer * pAP);
	virtual void SetAPEventsSource(struct Xcp_IAutomationPeer * pAP);
	virtual void * GetInteropHwnd();
	virtual XBOOL IsInteropPeer();
	virtual XBOOL SupportsWindowlessSiteHost();
	virtual void * GetWindowlessRawElementProviderSimple();
	virtual XBOOL IsPrevSiblingWindowless();
	virtual void * GetWindowlessSibling();
	virtual void * GetUnwrappedPattern(XINT32 patternID);
	virtual XUINT32 AddRef();
	virtual XUINT32 Release();

protected: 
	CAutomationPeer(CCoreServices *);
	HRESULT GetAutomationPeerStringValueFromManaged(enum UIAXcp::APAutomationProperties app, CXString * * ppString);
	HRESULT GetAutomationPeerIntValueFromManaged(enum UIAXcp::APAutomationProperties app, XINT32 * pRetVal);
	HRESULT GetAutomationPeerPointValueFromManaged(enum UIAXcp::APAutomationProperties app, struct XPOINTF * * ppPointF);
	HRESULT GetAutomationPeerRectValueFromManaged(enum UIAXcp::APAutomationProperties app, struct XRECTF_WH * * ppRectF);
	HRESULT GetAutomationPeerAPValueFromManaged(enum UIAXcp::APAutomationProperties app, struct Xcp_IAutomationPeer * * ppAP);
	void ClearChildrenList();
	CXcpList<IUIAProvider> * m_pPatternsList;
	struct IUIAWrapper * m_pUIAWrapper;
	CAutomationPeer * m_pAPParent;
	struct Xcp_IAutomationPeer * m_pAPEventsSource;
	CXString * pCurrentItemStatus;
	CXString * pCurrentName;
	XINT32 nCurrentIsOffscreen;
	XINT32 nCurrentIsEnabled;
	XINT32 m_iChildrenAddedTable[0x14];
	XINT32 m_iChildrenRemovedTable[0x14];
	XUINT32 m_nChildrenAdded;
	XUINT32 m_nChildrenRemoved;
	XUINT32 m_nRuntimeId;


};


